package com.imooc.distributedemo.rithm;

import org.hibernate.query.criteria.internal.expression.function.AggregationFunction.MAX;

public class ContainerAreaDemo {
    public static int caculateArea(int[] nums){
        int max = 0;
        for (int i = 0; i < nums.length-1; i++) {
            for (int j = i+1; j < nums.length; j++) {
                int area = (j-i) * Math.min(nums[i],nums[j]);
                max = Math.max(max,area);
            }
        }
        return max;
    }

    public static int maxArea(int[] nums){
        int max = 0;
        for (int i = 0; i < nums.length-1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                int minHeight = nums[i]<nums[j]?nums[i++]:nums[j--];
                max = Math.max(max,(j-i+1)*minHeight);
            }
        }
        return max;
    }

    public static void main(String[] args) {
        int []nums = {1,8,6,2,5,4,8,3,7};
        int result = maxArea(nums);//caculateArea(nums);
        System.out.println(result);
    }
}
